import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/www/index/index'),
    hidden: true
  },

  {
    path: '/quotes',
    component: () => import('@/www/quote/list'),
    hidden: true
  },

  {
    path: '/quote/sticker',
    component: () => import('@/www/quote/sticker/index'),
    hidden: true,
    meta: {
      title: '拼版不干胶',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/envelope',
    component: () => import('@/www/quote/envelope/index'),
    hidden: true,
    meta: {
      title: '信封',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/room-card-holder',
    component: () => import('@/www/quote/room-card-holder/index'),
    hidden: true,
    meta: {
      title: '房卡套',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/outdoor-printing',
    component: () => import('@/www/quote/outdoor-printing/index'),
    hidden: true,
    meta: {
      title: '户外写真',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/indoor-printing',
    component: () => import('@/www/quote/indoor-printing/index'),
    hidden: true,
    meta: {
      title: '室内写真',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/painted-cloth',
    component: () => import('@/www/quote/painted-cloth/index'),
    hidden: true,
    meta: {
      title: '喷绘布',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/hd-uv',
    component: () => import('@/www/quote/hduv/index'),
    hidden: true,
    meta: {
      title: '高清UV',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/tablet-uv',
    component: () => import('@/www/quote/tablet-uv/index'),
    hidden: true,
    meta: {
      title: '平板UV',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/acrylic-uv',
    component: () => import('@/www/quote/acrylic-uv/index'),
    hidden: true,
    meta: {
      title: '亚克力UV',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/display-shelf',
    component: () => import('@/www/quote/display-shelf/index'),
    hidden: true,
    meta: {
      title: '展示架',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/sb-sticker',
    component: () => import('@/www/quote/sb-sticker/index'),
    hidden: true,
    meta: {
      title: '商标不干胶',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/card',
    component: () => import('@/www/quote/card/index'),
    hidden: true,
    meta: {
      title: '名片报价',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/specialty-card',
    component: () => import('@/www/quote/specialty-card/index'),
    hidden: true,
    meta: {
      title: '特种纸名片',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/pvc-card',
    component: () => import('@/www/quote/pvc-card/index'),
    hidden: true,
    meta: {
      title: 'PVC名片报价',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/pvc-member-card',
    component: () => import('@/www/quote/pvc-member-card/index'),
    hidden: true,
    meta: {
      title: 'PVC会员卡',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/color-page',
    component: () => import('@/www/quote/color-page/index'),
    hidden: true,
    meta: {
      title: '彩页报价',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/album',
    component: () => import('@/www/quote/album/index'),
    hidden: true,
    meta: {
      title: '画册',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/note-pad',
    component: () => import('@/www/quote/note-pad/index'),
    hidden: true,
    meta: {
      title: '便签报价',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/joint-sheet',
    component: () => import('@/www/quote/joint-sheet/index'),
    hidden: true,
    meta: {
      title: '联单报价',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/quote/digital-page',
    component: () => import('@/www/quote/digital-page/index'),
    hidden: true,
    meta: {
      title: '数码单张',
      roles: ['ROLE_USER']
    }
  },
  {
    path: '/quote/digital-sticker',
    component: () => import('@/www/quote/digital-sticker/index'),
    hidden: true,
    meta: {
      title: '数码不干胶',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/submitOrder',
    component: () => import('@/www/submitOrder/index'),
    hidden: true,
    meta: {
      title: '提交订单',
      roles: ['ROLE_USER']
    }
  },

  {
    path: '/charge',
    component: () => import('@/www/charge/index'),
    hidden: true,
    meta: {
      title: '在线充值',
      roles: ['ROLE_USER']
    }
  },


  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/www/register/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
